﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;

namespace Interview_Prov.Admin
{
    public partial class UserAdd : System.Web.UI.Page
    {
        public Dictionary<int, string> Roles { get; set; }
        private Business.BusinessLogic bll = new Business.BusinessLogic();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Roles = bll.GetRoles();
                DataBind();
            }
        }

        protected void Create_Click(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                if (TextBox1.Text != string.Empty && TextBox2.Text != string.Empty)
                {
                    var roles = new List<string>();
                    roles=ListBox1.GetSelectedIndices().Select((x)=>(ListBox1.Items[x].Text)).ToList();
                    bll.AddUser(new User(TextBox1.Text,TextBox2.Text,roles));
                }
            }
        }
    }
}